Encoding values by pseudo-random mask

ABSTRACT

A method for a keyed cryptographic operation by a cryptographic system mapping an input message to an output message, including: receiving input data for the keyed cryptographic operation; calculating a first mask value based upon the input data; and applying the first mask value to a first intermediate value of the keyed cryptographic operation.

TECHNICAL FIELD

Various exemplary embodiments disclosed herein relate generally tosecuring software components that perform a cryptographic functionagainst attacks including encoding values by pseudo-random masks.

BACKGROUND

The Internet provides users with convenient and ubiquitous access todigital content. Because the Internet is a powerful distributionchannel, many user devices strive to directly access the Internet. Theuser devices may include a personal computer, laptop computer, set-topbox, internet enabled media player, mobile telephone, smart phone,tablet, mobile hotspot, or any other device that is capable of accessingthe Internet. The use of the Internet as a distribution medium forcopyrighted content creates the compelling challenge to secure theinterests of the content provider. Increasingly, user devices operateusing a processor loaded with suitable software to render (playback)digital content, such as audio and/or video. Control of the playbacksoftware is one way to enforce the interests of the content ownerincluding the terms and conditions under which the content may be used.Previously many user devices were closed systems. Today more and moreplatforms are partially open. Some users may be assumed to have completecontrol over and access to the hardware and software that providesaccess to the content and a large amount of time and resources to attackand bypass any content protection mechanisms. As a consequence, contentproviders must deliver content to legitimate users across a hostilenetwork to a community where not all users or user devices can betrusted.

Secure software applications may be called upon to carry out variousfunctions such as, for example, cryptographic functions used to protectand authenticate digital content. In order to counter attacks, thesealgorithms have to be obfuscated (hidden) in order to prevent reverseengineering and modification of the algorithm or prohibit obtaining theuser-specific secure information. Accordingly, the functions of thesecure software application may be carried out by various functions asdefined by the instruction set of the processor implementing the securesoftware. For example, one way to obscure these functions is by the useof lookup tables.

Content providers must deliver content to legitimate users across ahostile network to a community where not all users or devices can betrusted. This has led to the development of white-box cryptography. Inthe white-box cryptography scenario it is assumed that the user hascomplete control of the hardware and software that provides access tothe content, and an unlimited amount of time and resources to attack andbypass any content protection mechanisms. The secure software code thatenforces the terms and conditions under which the content may be usedshould be tamper resistant. Digital rights management is a commonapplication of secure software applications. The general approach indigital rights management for protected content distributed to userdevices is to encrypt the digital content using for example, DES (DataEncryption Standard), AES (Advanced Encryption Standard), or using otherknown encryption schemes, and to use decryption keys to recover thedigital content. These decryption keys must be protected to preventunauthorized access to protected material.

In the digital right management scenario, the attacker has completecontrol of the software enforcing the management and access to theprotected content. Accordingly, the attacker can modify software andalso seek to obtain cryptographic keys used to encrypt the protectedcontent. Such keys may be found by analyzing the software

Regarding key distribution, a media player has to retrieve a decryptionkey from a license database in order to play back the media. The mediaplayer then has to store this decryption key somewhere in memory for thedecryption of the encrypted content. This leaves an attacker two optionsfor an attack on the key. First, an attacker may reverse engineer thelicense database access function allowing the attacker to retrieve assetkeys from all license databases. In this situation the attacker does notneed to understand the internal working of the cryptographic function.Second, the attacker may observe accesses of the memory during contentdecryption, thus the attacker may retrieve the decryption key. In bothcases the key is considered to be compromised.

The widespread use of digital rights management (DRM) and other securesoftware has given rise to the need for secure, tamper-resistantsoftware that seeks to complicate tampering with the software. Varioustechniques for increasing the tamper resistance of software applicationsexist. Most of these techniques are based on hiding the embeddedknowledge of the application by adding a veil of randomness andcomplexity in both the control and the data path of the softwareapplication. The idea behind this is that it becomes more difficult toextract information merely by code inspection. It is therefore moredifficult to find the code that, for example, handles access andpermission control of the secure application, and consequently to changeit.

As used herein, white-box cryptography includes a secure softwareapplication that performs cryptographic functions in an environmentwhere an attacker has complete control of the system running thewhite-box cryptography software. Thus, the attacker can modify inputsand outputs, track the operations of the software, sample and monitormemory used by the software at any time, and even modify the software.Accordingly, the secure functions need to be carried out in a mannerthat prevents the disclosure of secret information used in the securefunctionality. White-box cryptography functions may be implemented invarious ways. Such methods include: obscuring the software code; usingcomplex mathematical functions that obscure the use of the secretinformation; using look-up tables; using finite state machines; or anyother methods that carry out cryptographic functions but hide the secretinformation needed for those secure functions. A white-boximplementation may also contain components that include anti-debuggingand tamper-proofing properties.

There are several reasons for preferring a software implementation of acryptographic algorithm to a hardware implementation. This may, forinstance, be the case because a software solution is renewable if thekeys leak out, because it is has lower cost, or because theapplication-developer has no influence on the hardware where thewhite-box system is implemented.

SUMMARY

A brief summary of various exemplary embodiments is presented below.Some simplifications and omissions may be made in the following summary,which is intended to highlight and introduce some aspects of the variousexemplary embodiments, but not to limit the scope of the invention.Detailed descriptions of an exemplary embodiment adequate to allow thoseof ordinary skill in the art to make and use the inventive concepts willfollow in later sections.

Various embodiments relate to a non-transitory machine-readable storagemedium encoded with instructions for execution by a keyed cryptographicoperation by a cryptographic system mapping an input message to anoutput message, including: instructions for receiving input data for thekeyed cryptographic operation; instructions for calculating a first maskvalue based upon the input data; and instructions for applying the firstmask value to a first intermediate value of the keyed cryptographicoperation.

Various embodiments are described, further comprising setting athreshold value ϵ, wherein the mask value based upon the input iscalculated such that for all values of b: |p_(a|b)−p_(a)|≤ϵ, wherep_(a|b) is the number of input values for which the masked value equalsa given that the first intermediate value equals b divided by the numberof values for which the intermediate value equals b, and where p_(a) isthe number of input values for which the masked value equals a dividedby the number of input values.

Various embodiments are described, wherein the threshold value E isselected based upon an expected number of traces collected by anattacker.

Various embodiments are described, wherein the cryptographic function isthe Advanced Encryption Standard (AES).

Various embodiments are described, wherein the cryptographic function isthe Data Encryption Standard (DES).

Various embodiments are described, wherein the input data and has Nportions and wherein instructions for calculating a first mask valuebased upon the input data further includes: instructions for applying Nbijective functions to each of the N portions of the input data; andinstructions for combining outputs of the N bijective functionsresulting in the first mask value.

Various embodiments are described, further including: instructions forcalculating second mask value based upon the input data that isdifferent from the first mask value; and instructions for applying thesecond mask value to a second intermediate value of the keyedcryptographic operation.

Various embodiments are described wherein the keyed cryptographicoperation includes a plurality of rounds with each round including aplurality of substitution functions, the outputs of the substitutionfunctions are combined to produce an output of the round, and theoutputs of the substitution functions are the first intermediate value.

Various embodiments are described, further including: applying the firstmask value to the output of the round to remove the first mask value.

Various embodiments are described wherein the keyed cryptographicoperation further includes: a first round of the keyed cryptographicoperation producing a first masked output; and a second round receivingthe first masked output wherein the second round compensates for themasking of the first masked output.

Further various embodiments relate to a method of controlling a serverthat provides an application that implements a keyed cryptographicoperation by mapping an input message to an output message, including:receiving a request from a user for the application that implements akeyed cryptographic operation by mapping an input message to an outputmessage; and providing the user the application that implements a keyedcryptographic operation by mapping an input message to an outputmessage, wherein the application was created by: receiving input datafor the keyed cryptographic operation; calculating a first mask valuebased upon the input data; and applying the first mask value to a firstintermediate value of the keyed cryptographic operation.

Various embodiments are described wherein the application was furthercreated by setting a threshold value ϵ, wherein the mask value basedupon the input is calculated such that for all values of b:|p_(a|b)−p_(a)|≤ϵ, where p_(a|b) is the number of input values for whichthe masked value equals a given that the first intermediate value equalsb divided by the number of values for which the intermediate valueequals b, and where p_(a) is the number of input values for which themasked value equals a divided by the number of input values.

Various embodiments are described wherein the threshold value E isselected based upon an expected number of traces collected by anattacker.

Various embodiments are described wherein the input data and has Nportions and wherein the application was further created by: applying Nbijective functions to each of the N portions of the input data; andcombining outputs of the N bijective functions resulting in the firstmask value.

Various embodiments are described wherein the application was furthercreated by: calculating second mask value based upon the input data thatis different from the first mask value; and applying the second maskvalue to a second intermediate value of the keyed cryptographicoperation.

Various embodiments are described wherein the keyed cryptographicoperation includes a plurality of rounds with each round including aplurality of substitution functions, the outputs of the substitutionfunctions are combined to produce an output of the round, and theoutputs of the substitution functions are the first intermediate value.

Various embodiments are described wherein the application was furthercreated by: applying the first mask value to the output of the round toremove the first mask value.

Various embodiments are described wherein the keyed cryptographicoperation further includes: a first round of the keyed cryptographicoperation producing a first masked output; and a second round receivingthe first masked output wherein the second round compensates for themasking of the first masked output.

Further various embodiments relate to a method for a keyed cryptographicoperation by a cryptographic system mapping an input message to anoutput message, including: receiving input data for the keyedcryptographic operation; calculating a first mask value based upon theinput data; and applying the first mask value to a first intermediatevalue of the keyed cryptographic operation.

Various embodiments are described, further comprising setting athreshold value ϵ, wherein the mask value based upon the input iscalculated such that for all values of b: |p_(a|b)−p_(a)|ϵ, wherep_(a|b) is the number of input values for which the masked value equalsa given that the first intermediate value equals b divided by the numberof values for which the intermediate value equals b, and where p_(a) isthe number of input values for which the masked value equals a dividedby the number of input values.

Various embodiments are described wherein the threshold value ϵ isselected based upon an expected number of traces collected by anattacker.

BRIEF DESCRIPTION OF THE DRAWINGS

In order to better understand various exemplary embodiments, referenceis made to the accompanying drawings, wherein:

FIG. 1 illustrates the main steps of a round of AES;

FIG. 2 illustrates a white-box AES implementation with fixed encodingson the input of the rounds;

FIG. 3 illustrates the computation of one output nibble by means of anetwork of look-up tables;

FIG. 4 illustrates a portion of the network table of FIG. 3 obfuscatedby encoding the inputs and outputs;

FIG. 5 illustrates a illustrates a network that computes a pseudo-randommask m;

FIG. 6 illustrates how the mask may be applied to the intermediatevalues present in the network of tables in FIG. 3; and

FIG. 7 illustrates a system for providing a user device secure contentand a software application that processes the secure content.

To facilitate understanding, identical reference numerals have been usedto designate elements having substantially the same or similar structureand/or substantially the same or similar function.

DETAILED DESCRIPTION

The description and drawings illustrate the principles of the invention.It will thus be appreciated that those skilled in the art will be ableto devise various arrangements that, although not explicitly describedor shown herein, embody the principles of the invention and are includedwithin its scope. Furthermore, all examples recited herein areprincipally intended expressly to be for pedagogical purposes to aid thereader in understanding the principles of the invention and the conceptscontributed by the inventor(s) to furthering the art, and are to beconstrued as being without limitation to such specifically recitedexamples and conditions. Additionally, the term, “or,” as used herein,refers to a non-exclusive or (i.e., and/or), unless otherwise indicated(e.g., “or else” or “or in the alternative”). Also, the variousembodiments described herein are not necessarily mutually exclusive, assome embodiments can be combined with one or more other embodiments toform new embodiments.

There are several reasons for preferring a software implementation of acryptographic algorithm to a hardware implementation. This may, forinstance, be the case because a software solution is renewable if thekeys leak out, because it is has lower cost, or because theapplication-developer has no influence on the hardware where thewhite-box system is implemented. While the description of embodimentsbelow are directed to software implementation running on a processor, itis noted that these embodiments may also be partially or completelyimplemented in hardware as well. The lookup tables and finite statemachines that are described may be implemented in hardware to carry outthe various functions described.

A table-based approach to a white-box implementation of the AdvancedEncryption Standard (AES) and the Data Encryption Standard (DES) wereproposed in the following papers: “White-Box Cryptography and an AESImplementation”, by Stanley Chow, Philip Eisen, Harold Johnson, and PaulC. Van Oorschot, in Selected Areas in Cryptography: 9th AnnualInternational Workshop, SAC 2002, St. John's, Newfoundland, Canada, Aug.15-16, 2002, referred to hereinafter as “Chow 1”; and “A White-Box DESImplementation for DRM Applications”, by Stanley Chow, Phil Eisen,Harold Johnson, and Paul C. van Oorschot, in Digital Rights Management:ACM CCS-9 Workshop, DRM 2002, Washington, D.C., USA, Nov. 18, 2002,referred to hereinafter as “Chow 2”. Chow 1 and Chow 2 disclose methodsof using a table-based approach to hide the cryptographic key by acombination of encoding its tables with random bijections, and extendingthe cryptographic boundary by pushing it out further into the containingapplication.

As noted, for many cryptographic operations it is desired to have awhite-box implementation. The invention may be applied, for example, tosymmetric and asymmetric cryptographic operations. Also, the inventionmay be applied to block ciphers, stream ciphers, message authenticationschemes, signature schemes, etc. Note that the invention may also beapplied to hash functions. The latter is especially useful if the hashfunction is used as a building block which processes secret information,e.g., a secret key, secret data, etc. For example, the invention may beapplied to a hash function used in a keyed-Hash Message AuthenticationCode (HMAC or KHMAC). Well known block ciphers include: AdvancedEncryption Standard (AES), Secure And Fast Encryption Routine, (SAFER,and variants SAFER+ and SAFER++), Blowfish, Data Encryption Standard(DES), etc. A well-known stream cipher is RC4. Moreover any block ciphercan be used as stream cipher using an appropriate mode of operation,e.g., Cipher feedback (CFB), Counter mode (CTR), etc.

The input message can represent, e.g., encrypted content data, such asmulti-media data, including audio and/or video data. The encryptedcontent data may also include encrypted software, e.g., encryptedcomputer code representing some computer application, e.g., a computergame, or an office application. The input message may also represent akey for use in a further cryptographic operation. The latter may beused, for example, in a key exchange protocol, wherein a white-boximplementation according to the invention encrypts and/or decrypts datarepresenting a new key. The input data may also be plain data, forexample, plain user data. The latter is especially advantageous inmessage authentication schemes. A white-box implementation according tothe invention may have the property that the implementation may only beused for encryption, only be used for decryption, but not for both. Forexample, this property can be achieved if the implementation useslook-up tables which are not bijective, for example, a look-up tablehaving more input bits than output bits. Accordingly, if a user only hasa white-box decryptor, he may verify a MAC code but not create new MACs.This strengthens the non-repudiation properties of such a messageauthentication scheme.

The white-box implementation may be implemented using a plurality ofbasic blocks. The plurality of basic blocks is interconnected, in thesense that some of the blocks build on the outputs of one or more of theprevious blocks. A basic block may be implemented in hardware, forexample, as a computer chip. A basic block may use a switch board, astate machine or any other suitable construction for implementingfunctions in computer hardware. A basic block may also be implemented insoftware running on a general purpose computer chip, e.g. amicroprocessor. For example, a basic block may use a plurality ofcomputer instructions, including arithmetical instructions, whichtogether implement the functionality of the basic block. A widely usedimplementation for the basic block, which may be used both in softwareand hardware, is a look-up table. For example, Chow 1 and Chow 2 takethis approach to implement the AES and DES block ciphers. A look-uptable implementation includes a list which lists for possible inputvalues, an output value. The input value may be explicit in the lookuptable. In that situation the look-up table implementation could map aparticular input to a particular output by searching in the list ofinput values for the particular input. When the particular input isfound the particular output is then also found. For example, theparticular output may be stored alongside the particular input.Preferably, the input values are not stored explicitly, but onlyimplicitly. For example, if the possible inputs are a consecutive range,e.g. of numbers or bit-strings, the look-up table may be restricted tostoring a list of the output values. A particular input number may,e.g., be mapped to the particular output which is stored at a locationindicated by the number. Further, finite state machines or codeobfuscation may be used to implement the white-box implementation.

For example, a look up table for a function may be created by computingthe output value of the function for its possible inputs and storing theoutputs in a list. If the function depends on multiple inputs theoutputs may be computed and stored for all possible combinations of themultiple inputs. Look-up tables are especially suited to implementnon-linear functions, which map inputs to output in irregular ways. Awhite-box implementation can be further obfuscated, as is explainedbelow, by applying to one or more of its look-up tables a fixedobfuscating input encoding and a fixed output encodings. The results ofapplying a fixed obfuscating input encoding and output encodings is thenfully pre-evaluated. Using this technique, a look-up table would bereplaced by an obfuscated look-up table which has the same dimensions,that it takes the same number input bits and produces the same number ofoutput bits. The input encoding and output encoding used in suchobfuscation are not explicit in the final white-box implementation.

The network of basic blocks are arranged to compute an output messagewhen they are presented with an input message. Typically, the inputmessage is operated upon by a number of basic input blocks. A number offurther basic blocks may take input from one or more of the basic inputblocks and/or from the input. Yet further basic blocks can take input inany combination of the input message, the output of basic input blocksand the output of the further basic blocks. Finally some set of basicexit blocks, i.e., at least one, produce as output all or part of theoutput-message. In this manner a network of basic blocks emerges whichcollectively computes the mapping from the input message to outputmessage.

The key used may be a cryptographic key and may contain sufficiententropy to withstand an anticipated brute force attack. It is noted thatin a white-box implementation, the key is typically not explicitlypresent in the implementation. This would risk the key being found byinspection of the implementation. Typically, the key is only presentimplicitly. Various ways are known to hide a key in a cryptographicsystem. Typically, at least the method of partial evaluation is used,wherein a basic block which needs key input is evaluated in-so-far thatit does not depend on the input-message. For example, a basic operationwherein an input-value, a masking value, which does not depend on theinput-message, e.g. a value from a substitution box (S-box), and akey-value need to be XORed can be partially evaluated by XORing the keyvalue and the masking value together beforehand. In this way theoperation still depends on the key-value although the key-value is notexplicitly present in the implementation. Instead, only the XOR betweenthe key-value and masking-value is present in the implementation. Notethat, more complicated ways and/or further ways of hiding the keys arecompatible with embodiments of this invention.

An interesting category of attacks on white-box implementations iscorrelation power analysis (CPA). These type of attacks work as follows.

An attacker collects a large number of execution traces for thewhite-box implementation, each with a different, but known plaintext. InCPA attacks, this trace is a power trace, but the traces may measureother different properties of the white-box implementation. The tracesmay be placed in a matrix t where t_(i,j) denotes the trace-value (e.g.,power consumption) at time point j for trace i.

Then, the attacker chooses some intermediate value v or a function ƒ(v)thereof in a standard implementation that has some relation to a limitednumber of key-bytes. Because ƒ(v) equals v if ƒ is the identityfunction, in the description below ƒ(v) is used for both cases.

The attacker then determines the value ƒ(v) in the standardimplementation for different guesses/hypotheses of the key bits on whichthe value depends and for the different plaintexts for which executiontrace data has been collected. For the ith plaintext and the jth keyhypothesis, this gives the value ƒ(v_(i,j)).

For each key hypothesis k and time point p, the attacker determines thecorrelation between ƒ(v_(i,k)) and t_(i,p) over all traces. For thecorrect key-hypothesis, the correlation will typically be higher thanfor an incorrect key-hypothesis. If this is the case, then there is keyleakage.

In hardware implementations where a white-box attack model is notassumed, attacks like this are typically prevented by adding randomnoise to the execution. This approach, however, does not work forwhite-box implementations because in a white-box attack model anadversary can disable the source generating the random data.

To harden an implementation against CPA-attacks, embodiments aredescribed that mask intermediate values of a cryptographic algorithm bypseudo-random masks. That is, by using masks that are function f of theinput to the algorithm. The implementation of f may be merged with theimplementation of the cryptographic algorithm in order to prevent anattacker from influencing or inspecting the pseudo random mask.White-box implementations are well-suited for this.

Below white-box embodiments are described using the AES (AdvancedEncryption Standard) block cipher, because AES has become a widely usedstandard for block ciphers. AES is a block cipher with a block size of128 bits or 16 bytes. The plaintext is divided in blocks of 16 byteswhich form the initial state of the encryption algorithm, and the finalstate of the encryption algorithm is the cipher text. At any given pointin the encryption algorithm these 16 bytes are the state of theencryption algorithm. To conceptually explain AES, the bytes of thestate are organized as a matrix of 4×4 bytes. AES includes a number ofrounds, which depend on the key size. Each round includes similarprocessing steps operating on bytes, rows, or columns of the statematrix, each round using a different round key in these processingsteps. In the discussion using AES as an example, it is noted that AESdefines a round in a specific manner. In the embodiments below, a roundis any grouping of steps that includes at least one non-linear mappingfunction, such as an S-box in AES. Accordingly, a round as describedbelow includes one non-linear mapping function and any combination ofother steps of the cryptographic function. Further, the boundary of theround may start with the non-linear mapping function, for example anS-box, or any other operation that may be merged with the non-linearmapping function, for example a key addition.

FIG. 1 illustrates some main processing steps of a round of AES. Theprocessing steps include:

-   -   AddRoundKey 110—each byte of the state is XORed with a byte of        the round key;    -   SubBytes 120—a byte-to-byte permutation using a lookup table;    -   ShiftRows 140—each row of the state is rotated a fixed number of        bytes; and    -   MixColumns 150—each column is processed using a modulo        multiplication in GF(28).    -   The steps SubBytes 120, ShiftRows 130, and MixColumns 150 are        independent of the particular key used. The key is applied in        the step AddRoundKey 110. Except for the step ShiftRows 140, the        processing steps can be performed on each column of the 4×4        state matrix without knowledge of the other columns. Therefore,        they can be regarded as 32-bit operations as each column        consists of four 8-bit values. Dashed line 150 indicates that        the process is repeated until the required number of rounds has        been performed.

Each of these steps or a combination of steps may be represented by alookup table or by a network of lookup tables. If the AddRoundKey 110step is implemented by XORing with the round key, then the key isvisible to the attacker in the white-box attack context. The AddRoundKey110 step can also be embedded in lookup tables, which makes it lessobvious to find out the key. In fact, it is possible to replace a fullround of AES by a network of lookup tables. For example, the SubBytes120, ShiftRows 130, and MixColumns 150 steps may be implemented usingtable lookups. Below a possible white-box implementation of AES insufficient detail is discussed to describe the embodiments of theinvention below, but further detailed descriptions of such animplementation are found in Chow 1. Also, other variations in the lookuptable implementation may be used which are within the scope of theinvention.

Both the table-based white-box implementations and the finite statemachine implementations have the property that all intermediate valuesin the implementation are encoded (as compared to a standardimplementation). Examples of white-box implementations using finitestate machines are disclosed in U.S. Patent Publication 2007/0014394entitled “Data Processing Method” and a presentation at the Re-trustSixth Quarterly Meeting entitled “Synchrosoft MCFACT™ Secure DataProcessing Technology” by Wulf Harder and Atis Straujums dated Mar. 11,2008, which each are hereby incorporated by reference for all purposesas if fully set forth herein. FIG. 2 illustrates a white-box AESimplementation with fixed encodings on the input of the rounds, i.e., onthe input of the S-boxes. As shown, each of the 16 input bytes areencoded by f_(i) and each of the output bytes are encoded by g_(i).

In order to describe embodiments of the invention, a basic descriptionof a table-based white-box AES implementation will be described. For amore detailed description of a method for implementing a table-basedwhite-box AES see Chow 1. Chow 1 illustrates a specific implementationthat breaks up certain functions using tables of specified sizes. It iswell understood that various other divisions of the tables may be maderesulting in different functions for the look-up tables and differentsizes. Further, while the embodiments of the invention described belowuse a table-based white-box implementation of AES, other ciphers andcryptographic functions may be implemented according to the embodimentsdescribed. Also, other types of white-box implementations may be usedinstead of the table-base implementation, for example, a finite-stateimplementation.

The description of the table-based white-box AES is split into twosteps. In the first step, a round of AES is described as a network oflookup tables. In the second step, the tables are obfuscated by encodingtheir input and output.

Step 1: Implementing AES as a Network of Lookup Tables.

AES operates on data blocks of 16 bytes. These are typically describedas a 4×4 byte matrix, called the state including bytes x_(1,1), x_(1,2),x_(1,3), . . . x_(4,4). A round of AES as described above with respectto FIG. 1 include the following operations: AddRoundKey 110, SubBytes120, ShiftRows 130, and MixColumns 140. The first two operations,AddRoundKey and SubBytes can be merged into a single T-box operation.That is, we can define a byte-to-byte function T_(i,j) for input bytex_(i,j) as T_(i,j)(x_(i,j))=S(x_(i,j)⊕k_(i,j)) where k_(i,j) is a singlebyte of a 16 byte round key based upon the AES key. Let y_(i,j) be theoutput of T_(i,j). The ShiftRows operations is just an index-renumberingof the output bytes y_(i,j). For ease of presentation, this operation isomitted in this description, but may be incorporated into the look-uptable implementing T_(i,j) or implemented as a separate manipulation ofthe state matrix. In the MixColumns step, an output byte z_(i,j) of theround is computed from the 4 output bytes y_(1,j), y_(2,j), y_(3,j), andy_(4,j) via the algebraic expression z_(l,j)=MC_(l,1)·y_(1,j)⊕MC_(l,2)·y_(2,j) ⊕MC_(l,3)·y_(3,j) ⊕MC_(l,4)·y_(4,j) in GF(28) for someconstants MC_(l,r).

Now define a lookup table for each byte-to-byte functionQ_(i,j,l)(x_(i,j))=MC_(l,i)·T_(i,j)(x_(i,j)) with i,j,l=1, 2, . . . ,16. Then any output byte z_(l,j) may be computed by XORing the resultsof these lookup tables, i.e.,z_(l,j)=Q_(1,j,l)(x_(1,j))⊕Q_(2,j,l)(x_(2,j))⊕Q_(3,j,l)(x_(3,j))⊕Q_(4,j,l)(x_(4,j)). Note that the index i, j, l of Q-box can beinterpreted as “the contribution of input byte i, j of a round to outputbyte 1, j of the round”. The XOR may be implemented to operate on eachof two nibbles (i.e., 4-bit values) as a lookup table to reduce the sizeof the XOR tables. Accordingly, the Q-box may be implemented to produceoutput nibbles so that the size of the tables is reduced. Therefore, thecomputation of each output byte z_(l,j) of an AES-round has beendescribed as a network of lookup tables. The network of lookup tables tocompute a single output nibble of byte z_(2,3) is shown in FIG. 3.

FIG. 3 illustrates the computation of one output nibble by means of anetwork of look-up tables. The superscript index (1) in the Q-boxesindicates that the tables only provide the first nibble of the output ofthe Q-box. A set of input bytes x_(1,3), x_(2,3), x_(3,3) and x_(4,3) inthe input state 310 are input into the Q-boxes 320, 322, 324, 326. Theoutputs u₁, u₂ of lookup tables 320 and 322 are fed into the XOR 330,and the outputs u₃, u₅ of lookup table 324 and XOR 330 are fed into theXOR 332. The outputs u₄, u₆ of table 326 and XOR 332 are fed into XOR334. The output of XOR 334 is the first nibble of the output z_(2,3) ofoutput state 340. The second nibble of the output z_(2,3) of outputstate 340 may be calculated in the same way using additional Q-boxesalong with a similar XOR network. Further, additional sets of tables maybe implemented to completely convert the input state 310 into the outputstate 340 by receiving a column of bytes from the input state andconverting them into the output of the corresponding column of theoutput state.

Step 2: Obfuscating the Tables and the Intermediate Values

In the implementation depicted in FIG. 3, the key may easily beextracted from the Q-boxes. Just applying the inverse MixColumnsmultiplication and the inverse S-box to the output reveals the plainAddRoundKey operation. To prevent this, the input and outputs of alllookup tables are encoded with arbitrary bijective functions. This isdescribed in Chow 1. This means that a lookup table is merged with anencoding function that encodes the output and with a decoding functionthat decodes the input. The encodings are chosen such that the outputencoding of one table matches the input encoding assumed in the nexttables. A portion of the implementation of FIG. 3 is depicted in FIG. 4for the first round. In this example, the input to the round is notencoded in order to be compliant with AES, but the output of the roundis encoded. The output encoding is handled in the next round. That is,unlike the first round, the second round (and the later rounds) assumesthat the input is encoded. Alternatively, the first round may receive anencoded input. This input encoding must then be applied elsewhere in thesoftware program containing the white-box implementation. Similarly, thelast round may or may not include an output encoding depending onwhether the output is to be AES compliant. Note that in the white-boximplementation obtained, both the lookup tables and the intermediatevalues are obfuscated.

FIG. 4 illustrates a portion of the network of tables of FIG. 3obfuscated by encoding the inputs and outputs. The lookup tables 420,422, 424, 426 correspond to lookup tables 320, 322, 324, 326 of FIG. 3.The inputs of lookup tables 420, 422, 424, 426 are encoded by functionsE₉, E₁₀, E₁₁, E₁₂, respectively. The outputs of lookup tables 420, 422,424, 426 are encoded by functions f₁, f₂, f₃, f₄, respectively. XOR 430corresponds to XOR 330. The inputs of XOR 430 decode input using f₁ ⁻¹and f₂ ⁻¹. The output of XOR 430 is then encoded by function f₅. In asimilar manner XORs 432, 434 have input decodings and output encodingsas illustrated. The output z_(2,3) is encoded using f₇.

Standard white-box implementations, like the table-based ones describedabove, Chow et al., and the finite-state-machine-based ones describedabove, are vulnerable to the CPA attack as mentioned above. It is knownin the literature that an intermediate value v may be protected againstCPA attacks by masking v via v_(m)=v⊕m where m is a true random number.The embodiments described herein replace the true random mask by a maskthat is a function of the input of the cryptographic algorithm. So, boththe mask and the value that should be hidden are given by a function ofthe input of the algorithm. Accordingly, for each input the mask will bedifferent and hence appear to an attacker to be random. This thwarts theCPA attack.

This may be more precisely formulated as follows. Let v be anintermediate value that is to be masked. Because v depends on the inputx of the cryptographic algorithm, v may be written as v=g(x) for somefunction g. Next, v is masked via v_(m)=v⊕m, where mask m is specifiedby the input x of the cryptographic algorithm. That is, m=ƒ(x) for somefunction ƒ. For readability and as an example, the XOR operation ⊕ isused as the masking function, however, this operation may also be otherbinary operations.

When using a true random number generator, the literature states thatthe property that v_(m) is pairwise independent of V and m is needed.Informally, this means that v_(m) does not leak any information on v orm. If a good random number generator is used, the first property will beeasy to satisfy. However, in the embodiments described herein, v and mare a function of the same parameter, viz.x. Hence, care must be taken.To formalize the property, the following notation is introduced. Thevalue p_(a|b) is the probability that the masked value v_(m) equals agiven that the intermediate value v equals b, and it may be calculatedas follows:

$p_{a{b}} = {\frac{\#_{x}\left( {v_{m} = {{a\bigwedge v} = b}} \right)}{\#_{x}\left( {v = b} \right)} = {\frac{\#_{x}\left( {{\left( {{{g(x)} \otimes {f(x)}} = a} \right)\bigwedge{g(x)}} = b} \right)}{\#_{x}\left( {{g(x)} = b} \right)}.}}$Analogously, the value {circumflex over (p)}_(a|b) is the probabilitythat the masked value v_(m) equals a given that the mask m equals b, andit may be calculated as follows:

${\hat{p}}_{a{b}} = {\frac{\#_{x}\left( {v_{m} = {{a\bigwedge m} = b}} \right)}{\#_{x}\left( {m = b} \right)} = {\frac{\#_{x}\left( {{\left( {{{g(x)} \otimes {f(x)}} = a} \right)\bigwedge{f(x)}} = b} \right)}{\#_{x}\left( {{f(x)} = b} \right)}.}}$Finally, the value p_(a) denotes the probability that the masked valuev_(m) equals a, and it may be calculated as follows:

$p_{a} = {\frac{\#_{x}\left( {v_{m} = a} \right)}{\#_{x}} = {\frac{\#_{x}\left( \left( {{{g(x)} \otimes {f(x)}} = a} \right) \right)}{\#_{x}}.}}$

Now, the properties may be formalized as:

-   -   for all b for which v=b can occur and for all a: p_(a|b)=p_(a);        and    -   for all b for which m=b can occur and for all a: {circumflex        over (p)}_(a|b)=p_(a).

Although in the ideal case these properties are true, these propertiesmay be relaxed a bit for practical situations. What is desired is thatthere is no difference in v_(m) for different underlying values v for alarge number of traces, e.g., 1 million traces. Thus the properties maybe relaxed to the following:

-   -   for all b for which v=b can occur and for all a:        p_(a|b)=p_(a)+ϵ, where ϵ is a small positive or negative number;        and    -   for all b for which m=b can occur and for all a: {circumflex        over (p)}_(a|b)=p_(a)+ϵ, where ϵ is a small positive or negative        number.

Furthermore, it is a goal to hide the intermediate value, but not themask. So, the first of these two properties has to be satisfied. Thesecond not per se.

What is still open in the formalization is value of ϵ. The value 1/ϵ isrelated to the number of traces needed in a CPA attack to exploit thedependence between v_(m) and v (or m). So, take |ϵ|<10⁻⁶ to let thenumber of required traces be larger than 1 million.

For readability, embodiments of masking intermediate values will beillustrated by extending the implementation visualized in FIG. 3.Encodings may next be applied as described above with respect to FIG. 4.

Now it will be shown how to mask the intermediate values u₅ and u₆ inFIG. 3. FIG. 5 illustrates a network that computes a pseudo-random maskm. The pseudo-random mask m is applied to the intermediate values.

The masking value m may be computed by m=ƒ(x₁, x₂, . . . ,x₁₆)=h₁(x₁)⊕h₂(x₂)⊕ . . . ⊕h₁₆(x₁₆), where each h_(i) may be a randombijective function and x₁, x₂, . . . , x₁₆ are the 16 input bytes. Asshown in FIG. 5 input bytes x₁ and x₂ are input into the functions h₁520 and h₂ 530. The outputs of the functions h₁ 520 and h₂ 530 are XORedtogether by XOR 510. The combination of the functions h₁ 520 and h₂ 530and the XOR 510 are shown as a single block and hence may, for example,be implemented as a single lookup table or as a plurality of lookuptables. The function h₃ 550 then operates on the input byte x₃ and theoutput is then XORed by the XOR 540 with the output from the XOR 510.This process continues until the final input byte x₁₆ is input to thefinal function h₁₆ 570 and the XOR 560 produces the final mask value m.

FIG. 6 illustrates how the mask may be applied to the intermediatevalues present in the network of tables in FIG. 3. The Q-boxes 620, 622,624, 626 correspond to the Q-boxes 320, 322, 324, 326 in FIG. 3.Further, the XORs 630, 632, 634 correspond to the XORs 330, 332, 334 inFIG. 3. In order to mask the intermediate values u₁, u₅, and u₆ anadditional XOR 640 may be added to the network of FIG. 3. The XOR 640XORs the mask m and u₁ resulting in the value u₁⊕m, which masks theintermediate value u₁. Because the one input to XOR 630 is the maskedvalue u₁⊕m the output from the XOR 630 is now the masked value u₅⊕m. Thesame is true for XOR 632 and XOR 634 which produce masked outputs. Theoutput of 634 is z_(2,3)⊕m which may be input into the XOR 650 whichremoves the mask by XORing with the mask value m (z_(2,3) ⊕M) to resultin the unmasked value z_(2,3), which is then input to the S-box of thenext round of operation.

The value z_(2,3) is input to the S-box of the next round. Removing themask before using z_(2,3) as input to the S-box results in afunctionally correct implementation. To further improve security, it maybe desirable to not remove the mask at the input of the S-box. This maybe realized by using multiplicative masks instead of additive masks andby applying embodiments found in U.S. patent application Ser. Nos.14/219,606 and 14/484,925, which are hereby incorporated by referencefor all purposes as if fully set forth herein.

In other embodiments, the calculation of the mask may be varied forapplication to different intermediate values. For example, the functionsh₁, h₂, . . . , h₁₆ may be randomly selected for each differentcalculation of a mask value for application to different intermediatevalues of the cryptographic function.

What remains, is showing that for u₅ and u₆ the added masks satisfy atleast the first of the following two properties:

-   -   For all b for which v=b can occur and for all a we have        p_(a|b)=p_(a)+ϵ, where ϵ is a small positive or negative number;        and    -   For all b for which m=b can occur and for all a we have        {circumflex over (p)}_(a|b)=p_(a)+ϵ, where ϵ is a small positive        or negative number.

Consider the first condition for intermediate value u₅. From thedefinition of Q_(i,j,l) it follows that the tables Q_(1,3,2) ⁽¹⁾ andQ_(2,3,2) ⁽¹⁾ which deliver u₁ and u₂ with u₅=u₁ ⊕u₂ are bothsurjective. Hence, for each b if follows that v=b may occur.

For example, fix values x₁ and x₂. Then by varying x₃, x₄, . . . , x₁₆each value for the mask m occurs with a probability of exactly

$\frac{1}{2^{4}} = {1/16}$(this is because m is a 4 bit value). This means that irrespective ofwhat is assumed regarding the values of x₁ and x₂, the probability thata mask has a given value is given by 1/16. As a result, the probabilitythat m is some value C given that v=u₅=b for any value b is 1/16 aswell. The following may now be derived:p _(a|b) =P(v _(m) =a|u ₅ =b)=P(m=a⊕b|u ₅ =b)= 1/16for any a, b. By the law of total probability, it follows that if aconditional probability is constant for all possible conditions, thenalso the unconditional probability equals this constant: hence, p_(a)=1/16. This proves p_(a|b)=p_(a)+ϵ for ϵ=0.

Next, consider the second condition above (which, as mentioned before,is not essential for the invention). As indicated, the probability thatm has some value C is 1/16 irrespective of the value of u₅. That is, thevariables m and u₅ are independent. Thus the following may be computed:{circumflex over (p)} _(a|b) =P(v _(m) a|m=b)=P(u ₅ =a⊕b|m=b)=P(u ₅=a⊕b)In the above described definition of Q_(i,j,l) each of the 16 possiblenibble values occurs exactly the same number of times. Hence, P(u₅=c)equals the constant value 1/16. This yields {circumflex over(p)}_(a|b)=1/16 for any a, b. Using, as before the law of totalprobability, this gives {circumflex over (p)}_(a|b)={circumflex over(p)}_(a)+ϵ for ϵ=0.

This completes the proof that u₅ was masked according to the embodimentsdescribed herein. This proof also applies to the masking of the

A method according to the embodiments of the invention may beimplemented on a computer as a computer implemented method. Executablecode for a method according to the invention may be stored on a computerprogram medium. Examples of computer program media include memorydevices, optical storage devices, integrated circuits, servers, onlinesoftware, etc. Accordingly, a white-box system may include a computerimplementing a white-box computer program. Such system, may also includeother hardware elements including storage, network interface fortransmission of data with external systems as well as among elements ofthe white-box system.

In an embodiment of the invention, the computer program may includecomputer program code adapted to perform all the steps of a methodaccording to the invention when the computer program is run on acomputer. Preferably, the computer program is embodied on anon-transitory computer readable medium.

Further, because white-box cryptography is often very complicated and/orobfuscated it is tedious for a human to write. It is therefore ofadvantage to have a method to create the cryptographic system accordingto the embodiments of the invention in an automated manner.

A method of creating the cryptographic system according to the inventionmay be implemented on a computer as a computer implemented method, or indedicated hardware, or in a combination of both. Executable code for amethod according to the invention may be stored on a computer programmedium. In such a method, the computer program may include computerprogram code adapted to perform all the steps of the method when thecomputer program is run on a computer. The computer program is embodiedon a non-transitory computer readable medium.

The cryptographic system described herein may be implemented on a userdevice such as a mobile phone, table, computer, set top box, smart TV,etc. A content provider, such as a television network, video streamservice, financial institution, music streaming service, etc., mayprovide software to the user device for receiving encrypted content fromthe content provider. That software may have the encryption key embeddedtherein as described above, and may also include binding strings asdescribed above. Then the content provider may send encrypted content tothe user device, which may then decrypt using the supplied software anduse the content.

FIG. 7 illustrates a system for providing a user device secure contentand a software application that processes the secure content. The systemincludes a content server 700, application server 780, user devices 750,752, and a data network 740. The user devices 750, 752 may requestaccess to secure content provided by the content server 700 via datanetwork 740. The data network can be any data network providingconnectivity between the user devices 750, 752 and the content server700 and application server 780. The user devices 750, 752 may be one ofa plurality of devices, for example, set top boxes, media streamers,digital video recorders, tablets, mobile phones, laptop computers,portable media devices, smart watches, desktop computers, media servers,etc.

The user request for access may first require the downloading of asoftware application that may be used to process the secure contentprovided by the content server 700. The software application may bedownloaded from the application server 780. The software application maybe obscured using the techniques described above as well as operate asdescribed above. Once the user devices 750, 752 install the softwareapplication, the user device may then download secure content from thecontent server 700 and access the secure content using the downloadedsoftware application. For example, the downloaded software applicationmay perform decryption of encrypted content received from the contentserver. In other embodiments, the software application may perform othersecure operations, such as for example, encryption, digital signaturegeneration and verification, etc.

The content server 700 may control the access to the secure contentprovided to the user devices 750, 752. As a result when the contentserver 700 receives a request for secure content, the content server 700may transmit the secure content to the requesting user device. Likewise,the application server 720 may control access to the softwareapplication provided to the user devices 750, 752. As a result when thecontent server 720 receives a request for the software application, theapplication server 720 may transmit the software application to therequesting user device. A user device requesting the softwareapplication or secure content may also be authenticated by therespective servers, before providing the software application or securecontent to the user device.

The content server 700 may include a processor 702, memory 704, userinterface 706, network interface 710, and content storage 712interconnected via one or more system buses 780. It will be understoodthat FIG. 7 constitutes, in some respects, an abstraction and that theactual organization of the components of the device 700 may be morecomplex than illustrated.

The processor 702 may be any hardware device capable of executinginstructions stored in memory 704 or storage 712. As such, the processormay include a microprocessor, field programmable gate array (FPGA),application-specific integrated circuit (ASIC), or other similardevices.

The memory 704 may include various memories such as, for example L1, L2,or L3 cache or system memory. As such, the memory 702 may include staticrandom access memory (SRAM), dynamic RAM (DRAM), flash memory, read onlymemory (ROM), or other similar memory devices.

The user interface 706 may include one or more devices for enablingcommunication with a user such as an administrator. For example, theuser interface 706 may include a display, a mouse, and a keyboard forreceiving user commands.

The network interface 710 may include one or more devices for enablingcommunication with other hardware devices. For example, the networkinterface 710 may include a network interface card (NIC) configured tocommunicate according to the Ethernet protocol. Additionally, thenetwork interface 710 may implement a TCP/IP stack for communicationaccording to the TCP/IP protocols. Various alternative or additionalhardware or configurations for the network interface 710 will beapparent.

The content storage 712 may include one or more machine-readable contentstorage media such as read-only memory (ROM), random-access memory(RAM), magnetic disk storage media, optical storage media, flash-memorydevices, or similar storage media. In various embodiments, the contentstorage 712 may store content to be provided to users.

The application server 720 includes elements like those in the contentserver 700 and the description of the like elements in the contentserver 700 apply to the application server 720. Also, the contentstorage 712 is replaced by application storage 732. Further, it is notedthat the content server and applications server may be implemented on asingle server. Also, such servers may be implemented on distributedcomputer systems as well as on cloud computer systems.

Any combination of specific software running on a processor to implementthe embodiments of the invention, constitute a specific dedicatedmachine.

As used herein, the term “non-transitory machine-readable storagemedium” will be understood to exclude a transitory propagation signalbut to include all forms of volatile and non-volatile memory. Further,as used herein, the term “processor” will be understood to encompass avariety of devices such as microprocessors, field-programmable gatearrays (FPGAs), application-specific integrated circuits (ASICs), andother similar processing devices. When software is implemented on theprocessor, the combination becomes a single specific machine.

It should be appreciated by those skilled in the art that any blockdiagrams herein represent conceptual views of illustrative circuitryembodying the principles of the invention.

Although the various exemplary embodiments have been described in detailwith particular reference to certain exemplary aspects thereof, itshould be understood that the invention is capable of other embodimentsand its details are capable of modifications in various obviousrespects. As is readily apparent to those skilled in the art, variationsand modifications can be effected while remaining within the spirit andscope of the invention. Accordingly, the foregoing disclosure,description, and figures are for illustrative purposes only and do notin any way limit the invention, which is defined only by the claims.

What is claimed is:
 1. A non-transitory machine-readable storage mediumencoded with instructions for execution by a keyed cryptographicoperation by a cryptographic system mapping an input message to anoutput message, comprising: instructions for receiving input data forthe keyed cryptographic operation; instructions for calculating a firstmask value based upon the input data; instructions for applying thefirst mask value to a first intermediate value of the keyedcryptographic operation; and instructions for setting a threshold valueϵ, wherein the mask value based upon the input is calculated such thatfor all values of b:|P_(a|b)−P_(a)|≤ϵ, where P_(a|b), is the number of input values forwhich the masked value equals a given that the first intermediate valueequals b divided by the number of values for which the intermediatevalue equals b, and where P_(a) is the number of input values for whichthe masked value equals a divided by the number of input values.
 2. Thenon-transitory machine-readable storage medium of claim 1, wherein thethreshold value ϵ is selected based upon an expected number of tracescollected by an attacker.
 3. The non-transitory machine-readable storagemedium of claim 1, wherein the cryptographic function is the AdvancedEncryption Standard (AES).
 4. The non-transitory machine-readablestorage medium of claim 1, wherein the cryptographic function is theData Encryption Standard (DES).
 5. The non-transitory machine-readablestorage medium of claim 1, wherein the input data and has N portions andwherein instructions for calculating a first mask value based upon theinput data further comprises: instructions for applying N bijectivefunctions to each of the N portions of the input data; and instructionsfor combining outputs of the N bijective functions resulting in thefirst mask value.
 6. The non-transitory machine-readable storage mediumof claim 1, further comprising: instructions for calculating second maskvalue based upon the input data that is different from the first maskvalue; and instructions for applying the second mask value to a secondintermediate value of the keyed cryptographic operation.
 7. Thenon-transitory machine-readable storage medium of claim 1, wherein thekeyed cryptographic operation includes a plurality of rounds with eachround including a plurality of substitution functions, the outputs ofthe substitution functions are combined to produce an output of theround, and the outputs of the substitution functions are the firstintermediate value.
 8. The non-transitory machine-readable storagemedium of claim 7, further comprising: applying the first mask value tothe output of the round to remove the first mask value.
 9. Thenon-transitory machine-readable storage medium of claim 7, wherein thekeyed cryptographic operation further comprises: a first round of thekeyed cryptographic operation producing a first masked output; and asecond round receiving the first masked output wherein the second roundcompensates for the masking of the first masked output.
 10. A method ofcontrolling a server that provides an application that implements akeyed cryptographic operation by mapping an input message to an outputmessage, comprising: receiving a request from a user for the applicationthat implements a keyed cryptographic operation by mapping an inputmessage to an output message; and providing the user the applicationthat implements a keyed cryptographic operation by mapping an inputmessage to an output message, wherein the application was created by:receiving input data for the keyed cryptographic operation; calculatinga first mask value based upon the input data; and applying the firstmask value to a first intermediate value of the keyed cryptographicoperation, wherein the application was further created by setting athreshold value ϵ, wherein the mask value based upon the input iscalculated such that for all values of b:|P_(a|b)−P_(a)|≤ϵ, where P_(a|b) is the number of input values for whichthe masked value equals a given that the first intermediate value equalsb divided by the number of values for which the intermediate valueequals b, and where P_(a) is the number of input values for which themasked value equals a divided by the number of input values.
 11. Themethod of claim 10, wherein the threshold value ϵ is selected based uponan expected number of traces collected by an attacker.
 12. The method ofclaim 10, wherein the input data and has N portions and wherein theapplication was further created by: applying N bijective functions toeach of the N portions of the input data; and combining outputs of the Nbijective functions resulting in the first mask value.
 13. The method ofclaim 10, wherein the application was further created by: calculatingsecond mask value based upon the input data that is different from thefirst mask value; and applying the second mask value to a secondintermediate value of the keyed cryptographic operation.
 14. The methodof claim 10, wherein the keyed cryptographic operation includes aplurality of rounds with each round including a plurality ofsubstitution functions, the outputs of the substitution functions arecombined to produce an output of the round, and the outputs of thesubstitution functions are the first intermediate value.
 15. The methodof claim 14, wherein the application was further created by: applyingthe first mask value to the output of the round to remove the first maskvalue.
 16. The method of claim 14, wherein the keyed cryptographicoperation further comprises: a first round of the keyed cryptographicoperation producing a first masked output; and a second round receivingthe first masked output wherein the second round compensates for themasking of the first masked output.
 17. A method for a keyedcryptographic operation by a cryptographic system mapping an inputmessage to an output message, comprising: receiving input data for thekeyed cryptographic operation; calculating a first mask value based uponthe input data; applying the first mask value to a first intermediatevalue of the keyed cryptographic operation; and setting a thresholdvalue ϵ, wherein the mask value based upon the input is calculated suchthat for all values of b:|P_(a|b)−P_(a)|≤ϵ, where P_(a|b) is the number of input values for whichthe masked value equals a given that the first intermediate value equalsb divided by the number of values for which the intermediate valueequals b, and where P_(a) is the number of input values for which themasked value equals a divided by the number of input values.
 18. Themethod of claim 17, wherein the threshold value ϵ is selected based uponan expected number of traces collected by an attacker.